package com.sharp.core.voxel;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.sharp.core.voxel.resource.Vox;
import com.sharp.core.voxel.resource.VoxelResource;

public class VoxelLoader {

	private static Map<String, VoxelResource> dataMap;

	static {
		dataMap = new HashMap<String, VoxelResource>();
	}
	
	public static VoxelResource get(String path) throws IOException {
		VoxelResource res = dataMap.get(path); 
		if ( res != null )
			return res;
		res = load(path);
		dataMap.put(path, res);
		return res;
	}
	
	public static VoxelResource load(String path) throws IOException {
		
		if ( path.trim().endsWith(".vox") ) {
			return new Vox(path);
		}
		
		return null;
	}
	
	public static VoxelResource load(File file) throws IOException {
		
		if ( file.getAbsolutePath().trim().endsWith(".vox") ) {
			return new Vox(file.getAbsolutePath().trim());
		}
		
		return null;
	}
}
